package com.wind.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Stream的使用：接合
 *
 * @author Wind
 * @date 2021-06-09
 */
public class Test10Stream {
    public static void main(String[] args) {

        List<Person> persons = new ArrayList<>();
        persons.add(new Person("张三", 7000, 34, "男", "陕西"));
        persons.add(new Person("李四", 8000, 24, "男", "河北"));
        persons.add(new Person("王五", 6000, 42, "女", "甘肃"));
        persons.add(new Person("王五", 9000, 12, "女", "上海"));
        // 将员工姓名用 “，” 拼接
        String nameStr = persons.stream().map(p -> p.getName()).collect(Collectors.joining(","));
        System.out.println(nameStr);

        List<String> strings = Arrays.asList("A", "B", "C", "D");
        // 将集合元素拼接成字符串
        String str = strings.stream().collect(Collectors.joining("-"));
        System.out.println(str);
    }
}
